package com.tyoue.analysis;


import com.tyoue.login.Login;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

public class Analysis {

    private File[] files;

    public void readFile(String dir) {
        File file = new File(dir);
        this.files = file.listFiles();
    }

    public void analysis() throws Exception {
        Writer writer = new FileWriter("C:\\Users\\User\\Desktop\\世纪城社区.csv");
        for (File file : files) {
            Document document = Jsoup.parse(file, "utf-8");
            Elements element = document.getElementsByClass("View_Td_Light");
            Element x = document.getElementById("lbl_xy");
            if (x == null)
                continue;
            String xy = x.text();
            String text = "";
            for (int i = 0; i < 25; i++) {
                if (i == 19)
                    text += "," + xy.replace(",", "，");
                else if (i < 12 || (i >= 14 && i < 19) || i > 22)
                    text += "," + element.get(i).text().replace(",", "，");
            }
            writer.write(text.substring(1) + "\n");
            writer.flush();
        }
        writer.close();
    }

    public static void main(String[] args) throws Exception {
        Analysis analysis = new Analysis();
        analysis.readFile(Login.DIC);
        analysis.analysis();
    }
}
